#include"UdpServe.hpp"
#include<stdlib.h>
int main(int argc, char *argv[]){
    if(argc!=3){
       LOG(FATAL, "please input port and ip\n");
       exit(0);
    }   
   int port= atoi(argv[1]);
    std::string ip=argv[2];
    int socketd=socket(AF_INET, SOCK_DGRAM, 0);
     if (socketd < 0) {
        LOG(FATAL, "socket error\n");
        exit(SOCKET_ERROR);
    } else {
        LOG(DEBUG, "clent socket create success, _socketd: %d\n", socketd);
    }
    struct sockaddr_in local;
    memset(&local, 0, sizeof(local));
    local.sin_family = AF_INET;
    local.sin_port = htons(port);
    local.sin_addr.s_addr = inet_addr(ip.c_str());
      while(1)
    {
        std::string line;
        std::cout << "Please Enter# ";
        std::getline(std::cin, line);
        socklen_t len=sizeof(local);
        sendto(socketd,line.c_str(),line.size(),0,(sockaddr*)&local,len);
        char buff[1024];
        struct sockaddr_in cli_sou;
         socklen_t len_ac=sizeof(cli_sou);
        int m= recvfrom(socketd,buff,sizeof(buff)-1,0,(sockaddr*)&cli_sou,&len_ac);
        buff[m]=0;
         std::cout <<"clint:"<<buff<<std::endl;
    }
}